home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: news.openu.ac.il!news
- From: shimoco@mail.tlm.openu.ac.il (Shimon Cohen)
- Subject: Re: i = atoi(NULL);
- Message-ID: <DLnJpF.ApL@cs.openu.ac.il>
- Sender: news@cs.openu.ac.il
- Nntp-Posting-Host: shimoco.ppp.openu.ac.il
- Organization: Open Univ. of Israel
- X-Newsreader: Forte Free Agent 1.0.82
- References: <DKwCsG.IGD@cs.openu.ac.il> <96009.103802DSEAMA41@portland.caps.maine.edu> <30F7F466.F43@imsisoft.com>
- Date: Tue, 23 Jan 1996 09:03:44 GMT
-
-
- Victor Bazarov <vbazarov@imsisoft.com> wrote:
-
- >Starduster wrote:
- >>
- >> In article <DKwCsG.IGD@cs.openu.ac.il>, shimoco@mail.tlm.openu.ac.il (Shimon
- >> Cohen) says:
- >> >Hi !
- >> >
- >> >What ANSI C says about:
- >> >i = atoi(NULL);
-
- >Actually, nothing specific.
- >------------------------------------------------------------------------------
- >7.10.1.2
- > int atoi(const char *nptr);
- >"The atoi function converts the initial portion of the string pointed by nptr
- >to int representation. Except for the behavior on error, it is equivalent to
- > (int)strtol(nptr, (char **)NULL, 10)
-
- >7.10.1.5
- > long int strtol(const char *nptr, char **endptr, int base);
- >[...]
- > "In other than "C" locale, additional implementation-defined subject sequence
- >forms may be accepted.
- > If the subject is empty or does not have the expected form, no conversion is
- >performed; ... If no conversion could be performed, zero is returned."
- >------------------------------------------------------------------------------
- >My advice -- check the pointer for being NULL before passing to atoi().
-
- >> One question: why does it matter? Why would you want to do such a thing?
- >> Just curious.
-
- >I think Shimon wanted to use atoi with the argument got from another function,
- >which returns NULL in case of empty input, errors, or the like.
-
- Thats right !
- I called atoi like this:
- i = atoi (strtok (input_str, ",");
- My compiler (BC4.0) docs says: "If no conversion could be performed,
- zero is returned." . I used this fact and it works fine. but not under
- the unix machine of my teacher :-(
-
- Shimon Cohen
- >> -Darryl
-
- >Victor.
-
- >--
- >Signature.
-
-
-